package com.test.fundible.fundible_05_process.widget;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import static com.test.fundible.fundible_00_utils.FundibleConfigs.Data_Action_Conta_fundiblect_Phone;

import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.test.fundible.R;
import com.test.fundible.fundible_05_process.Pro_fundiblecessIn_fundiblefo;
import com.test.fundible.fundible_05_process.Proces_fundiblesIn_fundiblefo_Data;
import com.test.fundible.fundible_00_http.OkHttpUtil;
import com.test.fundible.fundible_00_utils.FundibleUtil;

public class Input_fundibleViewMan_fundibleager extends BaseProc_fundibleessWid_fundiblegetManager {

    private TextView tit_fundibleleTv;
    private EditText inpu_fundibletEt;


    public Input_fundibleViewMan_fundibleager(View view, Proces_fundiblesIn_fundiblefo_Data data, String page){
        super(view,data,page);
    }

    @Override
    protected void in_fundibleit(){

        tit_fundibleleTv = mView.findViewById(R.id.vpi_tv_title);
        inpu_fundibletEt = mView.findViewById(R.id.vpi_et_input);

        setTi_fundibletle(mDa_fundibleta.getTitle_fundible());
        inpu_fundibletEt.setHint(mDa_fundibleta.getHint_fundible());

        //联系人电话输入数字
        if (mDa_fundibleta.getAction_fundible().equalsIgnoreCase(Data_Action_Conta_fundiblect_Phone)) inpu_fundibletEt.setInputType(InputType.TYPE_CLASS_NUMBER);

        //加纳卡号和卡名填充
        if (FundibleUtil.isGhana_fundible() && mDa_fundibleta.getParamName_fundible().equalsIgnoreCase("walletMobile")){
            inpu_fundibletEt.setText(FundibleUtil.getMobile_fundible());
        }
        if (FundibleUtil.isGhana_fundible() && mDa_fundibleta.getParamName_fundible().equalsIgnoreCase("walletUsername")){
            inpu_fundibletEt.setText(Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getRecipientName_fundible());
        }

        inpu_fundibletEt.setOnFocusChangeListener((v, hasFocus) -> OkHttpUtil.getInstance_fundible().uploadEventPoint(TAG, mDa_fundibleta.getParamName_fundible().toUpperCase()+"_INPUT",hasFocus ? "": getInp_fundibleut()));

    }

    @Override
    public boolean checkI_fundiblenput() {
        if (!mDa_fundibleta.isMustInput_fundible()) return true;
        return !TextUtils.isEmpty(inpu_fundibletEt.getText());
    }

    @Override
    public String getInp_fundibleut() {
        return inpu_fundibletEt.getText().toString().trim();
    }

    public void addTextChang_fundibleeListener(TextWatcher textWatcher){
        inpu_fundibletEt.addTextChangedListener(textWatcher);
    }

    public void setTi_fundibletle(String title){
        if (TextUtils.isEmpty(title)) tit_fundibleleTv.setVisibility(GONE);
        else {
            tit_fundibleleTv.setVisibility(VISIBLE);
            tit_fundibleleTv.setText(title);
        }
    }

}
